<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('区域管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<style>
    .bootstrap-tree-table .treetable-tbody td {
        white-space: normal !important;
    }

    .bootstrap-tree-table .treetable-bars .tool-right {
        float: left !important;
        left: 10px;
    }

    .table-striped .table > thead:first-child > tr:first-child > th {
        font-weight: normal;
        font-size: 13px;
        border: 1px solid #cccccc !important;
    }

    .bootstrap-tree-table .treetable-tbody td {
        border: 1px solid #cccccc !important;
        border-top: 0px solid #cccccc !important;
    }

    .select-list li p {
        width: 20px !important;
    }

</style>
<body class="gray-bg">

<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 项目名称
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="project()" title="管理项目"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新项目"><i
                        class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>


<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="region-form">
                    <input type="hidden" id="companyId" name="companyId">
                    <input type="hidden" id="companyName" name="companyName">
                    <input type="hidden" id="proId" name="proId">
                    <input type="hidden" id="programId" name="programId">
                    <input type="hidden" id="programName" name="programName">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p style="width: 90px !important;">项目名称：</p>
                                <!--<input type="text" name="programName" id="progName" class="form-control"-->
                                <!--autocomplete='off' >-->

                                <div class="col-lg-2" style="margin-left: -15px">
                                    <input type="text" class="form-control" name="programName" id="progName" autocomplete='off'/>
                                </div>

                            </li>
                            <li style="margin-left: -15px">
                                <p style="width: 90px !important;" >楼号：</p>
                                <input type="text" name="buildingNumber" id="buildingNumber" class="form-control"
                                       autocomplete='off' onkeyup="value=value.replace(/[^\d]/g,'')">
                            </li>
                            <li>
                                <p style="width: 90px !important;">楼层：</p>
                                <input type="text" name="floorNumber" id="floorNumber" class="form-control"
                                       autocomplete='off' onkeyup="value=value.replace(/[^\d]/g,'')">
                            </li>

                            <li>
                                <p style="width: 90px !important;">浇筑日期：</p>
                                <input type="text" id="pouringTime" name="pouringTime" class="form-control" autocomplete='off'>

                            </li>
                            <li>
                                <p style="width: 90px !important;">设计标号：</p>
                                <input type="text" name="designLabel" id="designLabel" class="form-control"
                                       autocomplete='off' onkeyup="value=value.replace(/[^\d]/g,'')">
                            </li>
                            <li>
                                <p style="width: 90px !important;">龄期：</p>
                                <input type="text" name="age" id="age" class="form-control"
                                       autocomplete='off' onkeyup="value=value.replace(/[^\d]/g,'')">
                            </li>

                            <li style="margin-left: 50px">
                                <a class="btn btn-primary btn-rounded btn-sm" id="search" onclick="$.table.search()" ><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" id="add"
                   onclick="addView($('#companyId').val(),$('#proId').val(),$('#programName').val())">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>

                <a class="btn btn-warning" onclick="exportExcel('混凝土强度试验检测统计表')">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-suggest-js" />
<th:block th:include="include :: bootstrap-typeahead-js" />


<script th:inline="javascript">

    /* 模块前缀url */
    var prefix = ctx + "concreteManage";

    // $('#progName').typeahead({
    //     source: ["琅琊金鹏99广场项目","清风明月系","测试","琅琊项目测试"]
    // });


    $.get(ctx + "concreteManage/collection", function(data){
        $("#progName").typeahead({
            source: data.value
        });
    },'json');

    // var testBsSuggest = $("#suggest-demo-1").bsSuggest({
    //     url: ctx + "demo/form/userModel",
    //     idField: "userId",
    //     keyField: "userName"
    // }).on('onDataRequestSuccess', function (e, result) {
    //     console.log('onDataRequestSuccess: ', result);
    // }).on('onSetSelectValue', function (e, keyword) {
    //     console.log('onSetSelectValue: ', keyword);
    // }).on('onUnsetSelectValue', function (e) {
    //     console.log("onUnsetSelectValue");
    // });

    /* 初始化方法 */
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 300});

        // 初始化列表
        queryConcreteList();

        // 初始化树组件
        queryProjectTree();

        // 初始化日期控件
        formatDate();

        // 隐藏添加按钮
        $('#add').hide();
    });

    /* 初始化 列表信息 */
    function queryConcreteList() {
        var options = {
            uniqueId: "checkId",
            url: prefix + "/list",
            createUrl: prefix + "/add{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            pagination: true,
            modalName: "混凝土报表",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'checkId',
                    align: 'center',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'companyName',
                    align: 'center',
                    title: '工程公司'
                },
                {
                    field: 'programName',
                    align: 'center',
                    title: '项目名称'
                },
                {
                    field: 'buildingNumber',
                    align: 'center',
                    title: '工程部位',
                    sortable: true
                },
                {
                    field: 'floorNumber',
                    align: 'center',
                    title: '结构部位',
                    sortable: true
                },
                {
                    field: 'pouringTime',
                    align: 'center',
                    title: '浇筑日期',
                    sortable: true
                },
                {
                    field: 'checkTime',
                    align: 'center',
                    title: '检测日期',
                    sortable: true
                },
                {
                    field: 'age',
                    align: 'center',
                    title: '龄期'
                },
                {
                    field: 'designLabel',
                    align: 'center',
                    title: '设计标号(Mpa)'
                },

                {
                    field: 'averIntensity',
                    align: 'center',
                    title: '强度平均(Mpa)'
                },
                {
                    field: 'minIntensity',
                    align: 'center',
                    title: '强度最小(Mpa)'
                },
                {
                    field: 'note',
                    align: 'center',
                    title: '碳化深度'
                },
                {
                    field: 'checkPerson',
                    align: 'center',
                    title: '录入人员'
                },
                {
                    field: 'testPerson',
                    align: 'center',
                    title: '检测人员'
                },
                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.checkId + '\',\'' + row.programName + '\',\'' + row.companyId + '\',\'' + row.programId + '\',)"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.checkId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    /* 初始化 树组件 */
    function queryProjectTree() {
        var url = prefix + "/treeData";
        var options = {
            url: url,
            expandLevel: 0,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            if (treeNode.grade == 1) {
                $("#companyId").val(treeNode.id);
                $("#proId").val("");
                $('#add').hide();
                $("#programId").val("");
                $("#programName").val("");
                $.table.search()
            } else if (treeNode.grade == 2) {
                $("#companyId").val(treeNode.pId);
                $("#proId").val(treeNode.id);
                $("#programId").val(treeNode.id);
                $("#programName").val(treeNode.name);
                $('#add').show();
                $.table.search()
            }
        }
    }

    /* 添加按钮 */
    function addView(companyId, proId, programName) {
        var url = "/concreteManage/add?companyId=" + companyId + "&proId=" + proId + "&programName=" + programName;
        $.modal.openTab("添加" + table.options.modalName, url);
    }

    /* 编辑按钮 */
    function edit(checkId,programName,companyId,programId) {
        var url = prefix + '/editListView?checkId=' + checkId+'&programName='+programName+'&companyId='+companyId+'&programId'+programId;
        $.modal.openTab("报表编辑", url);
    }

    /* 导出按钮 */
    function exportExcel(fileName) {
        var data = {
            companyId: $("#companyId").val(),
            programId: $("#programId").val(),
            programName: $("#progName").val(),
            buildingNumber: $("#buildingNumber").val(),
            floorNumber: $("#floorNumber").val(),
        }

        $.modal.confirm("确定导出所有" + table.options.modalName + "吗？", function () {
            $.modal.loading("正在导出数据，请稍后...");
            $.post(table.options.exportUrl, data, function (result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + fileName + ".xls&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }

    /* 初始化树组件 > 展开 */
    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    /* 初始化树组件 > 折叠 */
    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    /* 初始化树组件 > 刷新 */
    $('#btnRefresh').click(function () {
        queryProjectTree();
    });

    function formatDate() {
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            laydate.render({
                elem: '#pouringTime'
            });

        });
    }


</script>
</body>
</html>